package fastas3
{
	import flash.utils.Dictionary;
	
	public class FastData
	{
		private static const DATA:FastData = new FastData(null, null);
		
		internal var name:String;
		internal var owner:FastObject;
		
		internal static function createData(owner:FastObject, name:String):FastData {
			DATA.name = name;
			DATA.owner = owner;
			return DATA;
		}
		
		public function FastData(owner:FastObject, name:String) {
			this.owner = owner;
			this.name = name;
		}
		
		public function exists():Boolean {
			return owner._hasData(name);
		}
		
		public function get():Object {
			return owner._getData(name);
		}
		
		public function set(value:Object):FastObject {
			return owner._setData(name, value);
		}
		
		public function add(value:Object):FastObject {
			return owner._addData(name, value);
		}
		
		public function save():FastObject {
			return owner._setData("_data_" + name, owner._getData(name));
		}
		
		public function load():Object {
			return owner._getData("_data_" + name);
		}
		
		public function restore():FastObject {
			return owner._setData(name, owner._getData("_data_" + name));
		}
	}
}